//
//  ViewController.m
//  01 -- 按钮操作
//
//  Created by Rainy Zou on 15/11/16.
//  Copyright © 2015年 Rainy Zou. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (void) btnClickWithBlock:(void (^)())myblock{
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    myblock();
    [UIView commitAnimations];
}


#pragma mark 移动操作
- (IBAction)move:(id)sender {
    
    [self btnClickWithBlock:^{
        int tag = [sender tag];
        CGRect frame = self.result.frame;
        float delta = 20;
        
        switch (tag) {
            case 1:
                frame.origin.y -=delta;
                break;
            case   2:
                frame.origin.x +=delta;
                break;
            case 3:
                frame.origin.y +=delta;
                break;
            case 4:
                frame.origin.x -=delta;
                break;
            default:
                break;
        }
        self.result.frame = frame;
    }];
    
}

#pragma mark 旋转操作，主要控制 UIView transform
- (IBAction)rotate:(id)sender {
    
    [self btnClickWithBlock:^{
        int tag = [sender tag];
        self.result.transform = CGAffineTransformRotate(self.result.transform,(tag ==10?-M_PI_4:M_PI_4));
    }];
}


#pragma mark 缩放操作，主要控制 UIView transform
- (IBAction)scale:(id)sender {
    [self btnClickWithBlock:^{
        int tag = [sender tag];
        
        CGFloat delta = 20 ==tag ? 1.2:0.8;
        
        self.result.transform = CGAffineTransformScale(self.result.transform,delta,delta);

    }];
    
}

#pragma mark 主要是还原操作过的 transform 对象
- (IBAction)reset:(id)sender {
    [self btnClickWithBlock:^{
        self.result.transform = CGAffineTransformIdentity;
    }];
}
@end
